package com.hxx.day6;

import org.junit.Test;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class TestDemo2 {

    /**
     * 消费型接口
     */
    @Test
    public void test1(){
        Consumer<String> consumer = (s) -> System.out.println(s);
        consumer.accept("hello");
    }
    /**
     * 消费型接口  消费一个对象
     */
    @Test
    public void test2(){
        Consumer<Student> consumer = (s) -> System.out.println(s.getName());
        consumer.accept(new Student("张三",18));
    }

    public void show(String str,Consumer<String> consumer){
        consumer.accept(str);
    }
    @Test
    public void test3(){
        show("hello",(s) -> System.out.println(s));
    }
    /**
     * 供给型接口
     */
    @Test
    public void test4(){
        Supplier<Student> supplier = () -> new Student("张三",18);
        Student student = supplier.get();
        System.out.println(student);
    }
    @Test
    public void test5(){
        Supplier<Integer> supplier = () -> 100;
        int i = supplier.get();
        System.out.println(i);
    }
    /**
     * 函数型接口
     */
    @Test
    public void test6(){
        Function<String,Integer> function = (s) -> s.length();
        int i = function.apply("hello");
        System.out.println(i);
    }
    @Test
    public void test7(){
        Function<Student,Integer> function = (s) -> s.getAge();
        int i = function.apply(new Student("张三",18));
        System.out.println(i);
    }
    public String method(Function<Student,String> function){
        return function.apply(new Student("张三",18));
    }
    @Test
    public void test8(){
        String s = method((s1) -> s1.getName());
        System.out.println(s);
    }
    /**
     * 断言型接口
     */
    @Test
    public void test9(){
        Predicate<Student> predicate = (s) -> s.getAge() > 18;
        boolean b = predicate.test(new Student("张三",20));
        System.out.println(b);
    }
}























